﻿/**
 * Created by masque on 2017/2/25.
 */
var canshow = true;
var cannum = true;
var toasts = new Array();
function showToast_xx(msg,timeout){
    console.log(msg,timeout);
    if(canshow) {
        canshow = false;
        var toastp = $("#showtoastp");
        console.log(toastp.length);
        if (!toastp||toastp.length==0) {
            console.log("添加元素",!toastp);
            var inner = '<div style="position: fixed;top: 0;right: 0;left: 0;bottom: 0;" id="onlyPopup">' +
                '<div style="display: table;width: 100%;height: 100%;">' +
                '<div style="display: table-cell;vertical-align: middle;">' +
                '<div style="width: 100px;background-color: rgba(0,0,0,0.78);border-radius: 4px;margin-left: auto;margin-right: auto;">' +
                '<div style="padding: 15px 15px;">'+
                '<p id= "showtoastp" style="font-size: 13px;color: #ffffff;text-align: center;"></p>' +
                '</div></div></div></div></div>';
            $('body').after(inner);
            toastp = $("#showtoastp");
        }
        toastp.html(msg);
        $('#onlyPopup').css({
            display: 'block',
            opacity: 1
        });
        setTimeout(hide,timeout);
    }else if(cannum){
        toasts.push({"msg":msg,"timeout":timeout});
    }
}
function hide(){
    $('#onlyPopup').animate({
        opacity:0
    },300,'swing',function(){
        canshow = true;
        $('#onlyPopup').css('display','none');
        if(toasts&&toasts.length>0){
            cannum = false;
            var msg = toasts.shift();
            showToast_xx(msg.msg,msg.timeout);
        }
    });
}
